// 引入文件
require("../../assets/css/index.less")
require("./addcircle.less");
require("../../assets/fonts/iconfont.css");

// 2.引入工具函数utils
const dom = require('../../utils/dom')
const https = require("../../utils/https")

//引入样式
require('../../lib/weui/weui.css');
//引入js库
let weui = require('../../lib/weui/weui.js');


dom.ready(function(){
    dom.addEvent('#backBtn',function(){
        location.href='circle.html'
    })

    // 省
    let provlaue;
    dom.addEvent('#proBtn', function() {
        https.get('/api/shared/province', function(res) {
            console.log(res);
            // 解构赋值
            let { errno, data } = res
            if (errno == 0) {
                let proDate = data.map(function(v) {
                    return {
                        value: v.id,
                        label: v.name
                    }
                })
                console.log(proDate);
                weui.picker(
                    proDate, {

                        onConfirm: function(result) {
                            console.log(result)
                            console.log(result[0].label);

                            dom.getEle('#proTxt').innerHTML = result[0].label;
                            provlaue = result[0].value
                        },
                        title: '省份选择'
                    })
            }
        })
    })

    // 城市
    let cityDate
    dom.addEvent('#cityBtn', function() {
        if (provlaue) {
            https.get('/api/shared/city?provinceId=' + provlaue, function(res) {
                console.log(res);
                // 解构赋值
                let { errno, data } = res
                if (errno == 0) {
                    let proDate = data.map(function(v) {
                        return {
                            value: v.id,
                            label: v.name
                        }
                    })
                    console.log(proDate);
                    weui.picker(
                        proDate, {

                            onConfirm: function(result) {
                                console.log(result)
                                console.log(result[0].label);

                                dom.getEle('#cityTxt').innerHTML = result[0].label;
                                cityDate = result[0].value

                            },
                            title: '城市选择'
                        })
                }
            })
        } else {
            weui.alert('请先输入省份')
        }

    })


})